<template>
	<div class="main">
		<div class="outerDiv">
			<go-back aa='../chooseCourse/chooseRecds'></go-back>
			<scroller style="top: 0.88rem;">
				<!-- 	<Header></Header> -->
				<div class="main">
					<div>
						<h1 class="title">优势科目测评</h1>
						<CardLineStep rightTitle="学习成绩测试" :hasWrite="step1" :circleTip="step1 ? '√' : '1'" :isCircleFinish="step1"
						 :isTopLineFinish="step > 0" :isBottomLineFinish="step > 1" :nextStep="2" :finishStep="step" :isStart="isStart"></CardLineStep>
						<CardLineStep rightTitle="科目兴趣测试" :hasWrite="step2" :circleTip="step2? '√' : '2'" :isCircleFinish="step2"
						 :isTopLineFinish="step > 1" :isBottomLineFinish="step > 2" :nextStep="3" :finishStep="step"></CardLineStep>
						<CardLineStep rightTitle="学习方法测试" :hasWrite="step3" :circleTip="step3 ? '√' : '3'" :isCircleFinish="step3"
						 :isTopLineFinish="step > 2" :isBottomLineFinish="step > 3" :nextStep="4" :finishStep="step"></CardLineStep>
						<CardLineStep rightTitle="师资水平测试" :hasWrite="step4" :circleTip="step4 ? '√' : '4'" :isCircleFinish="step4"
						 :isTopLineFinish="step > 3" :isBottomLineFinish="step > 4" :nextStep="5" :finishStep="step"></CardLineStep>
						<CardLineStep rightTitle="家长意见测试" :hasWrite="step5" :circleTip="step5 ? '√' : '5'" :isCircleFinish="step5"
						 :isTopLineFinish="step > 4" :isBottomLineFinish="step > 5" :nextStep="6" :finishStep="step"></CardLineStep>
						<CardLineStep rightTitle="同学意见测试" :hasWrite="step6" :circleTip="step6 ? '√' : '6'" :isTopLineFinish="step > 5"
						 :isBottomLineFinish="step > 6" :isCircleFinish="step6" :nextStep="7" :finishStep="step" :isEnd="isEnd"></CardLineStep>
					</div>
					<div style="width: 7.5rem;height: 3rem;"></div>
				</div>
			</scroller>
			<div class="footer">
				<div class="top">
					<div class="top_1">
						<b>测试完成</b>
						<span class="num"><b>{{lens}}</b>/6</span>
					</div>
					<div class="top_2">
						<!-- 生成剩余次数: 2 -->
					</div>
				</div>
				<div class="bottom">
					<button :class="['btn','createNew',lens<6?'cre1':'cre2']" @click="sunCase">生成新的综合测试排序</button>
					<!-- <button class="btn watchResult">查看综合测试排序结果</button> -->
				</div>
			</div>
		</div>
	</div>
</template>

<script>
	import CardLineStep from '~/components/CardLineStep'

	import goBack from '~/components/goBack'
	import Header from '~/components/Header'
	import axios1 from '~/plugins/axios1';
	import ls from 'store2'
	export default {
		components: {
			CardLineStep,
			Header,
			goBack
		},
		data() {
			return {
				isEnd: true,
				isStart: true,
				step: 3,
				step1: '',
				step2: '',
				step3: '',
				step4: '',
				step5: '',
				step6: '',
				dolist: [],
				lens: 0,
				ids: ''
			}
		},
		created() {
			this.commonJs.gologins();
		},

		mounted: function() {
			this.getEvaluation()
			if(this.commonJs.isTerminal()=='isAndroid'){
			if (window.history && window.history.pushState) {
				history.pushState(null, null, document.URL);
				window.addEventListener('popstate', this.fun, false); //false阻止默认事件 
			}
			}
		},
		destroyed() {
			// this.commonJs.xahui('../chooseCourse/chooseRecds')
			window.removeEventListener('popstate', this.fun, false);
		},
		methods: {
			fun() {
				this.$router.replace({
					path: '../chooseCourse/chooseRecds'

				})

			},
			sunCase() {
				if (this.lens < 6) {
					return false;
				}
				let a1 = JSON.parse(this.step1) //学习成绩测试
				let a2 = JSON.parse(this.step2) //科目兴趣测试
				let a3 = JSON.parse(this.step3) //学习方法测试
				let a4 = JSON.parse(this.step4) //师资水平测试
				let a5 = JSON.parse(this.step5) //家长意见测试
				let a6 = JSON.parse(this.step6) //同学意见测试
				let dili = 5 * a1.rate1 + 4 * a2.rate1 + 4 * a3.rate1 + 3 * a4.rate1 + 3 * a5.rate1 + 1 * a6.rate1;
				let lishi = 5 * a1.rate2 + 4 * a2.rate2 + 4 * a3.rate2 + 3 * a4.rate2 + 3 * a5.rate2 + 1 * a6.rate2;
				let zhenzhi = 5 * a1.rate3 + 4 * a2.rate3 + 4 * a3.rate3 + 3 * a4.rate3 + 3 * a5.rate3 + 1 * a6.rate3;
				let wuli = 5 * a1.rate4 + 4 * a2.rate4 + 4 * a3.rate4 + 3 * a4.rate4 + 3 * a5.rate4 + 1 * a6.rate4;
				let huaxue = 5 * a1.rate5 + 4 * a2.rate5 + 4 * a3.rate5 + 3 * a4.rate5 + 3 * a5.rate5 + 1 * a6.rate5;
				let senwu = 5 * a1.rate6 + 4 * a2.rate6 + 4 * a3.rate6 + 3 * a4.rate6 + 3 * a5.rate6 + 1 * a6.rate6;


				var datas = {
					"地理": {
						"num": dili
					},
					"历史": {
						"num": lishi
					},
					"政治": {
						"num": zhenzhi
					},
					"物理": {
						"num": wuli
					},
					"化学": {
						"num": huaxue
					},
					"生物": {
						"num": senwu
					}
				}

				// console.log('objs',objs)
				this.createReport(JSON.stringify(datas))
				// console.log('dili', typeof(JSON.stringify(datas)))
			},
			getEvaluation() {
				console.log(' ls.get.userType', ls.get('userType'))
				axios1.posts('/curricula/getEvaluation?userType=' + ls.get('userType')).then(res => {
					if (res.code === '0') {
						this.step1 = res.data.score;
						console.log('thisss', this.step1)
						this.step2 = res.data.interest;
						this.step3 = res.data.method;
						this.step4 = res.data.standard;
						this.step5 = res.data.patriarch;
						this.step6 = res.data.schoolmate;
						this.ids = res.data.id;
						if (this.step1) {
							this.lens += 1
						}
						if (this.step2) {
							this.lens += 1
						}
						if (this.step3) {
							this.lens += 1
						}
						if (this.step4) {
							this.lens += 1
						}
						if (this.step5) {
							this.lens += 1
						}
						if (this.step6) {
							this.lens += 1
						}
						// this.lens = Object.keys(res.data).length-1
						console.log('sssswww', this.lens)


						// this.$vux.toast.text(res.message);

					}
				}).catch(() => {
					// this.$vux.toast.text('服务器繁忙，请稍后再试');
				})
			},
			getSchemeRecord() {
				axios1.posts('/curricula/getSchemeRecord?userType=' + ls.get('userType')).then(res => {
					if (res.code === '0') {

					}
				}).catch(() => {
					this.$vux.toast.text('服务器繁忙，请稍后再试');
				})
			},
			createReport(data) {
				let obj = {
					generate: 3,
					ranking: data,
					id: this.ids
				}
				axios1.post('/curricula/createReport', obj, true).then(res => {
					if (res.code === '0') {
						this.$vux.toast.text(res.message);
						setTimeout(() => {
							this.commonJs.gosto('chooseRecds')
						}, 50)
					}
				}).catch(() => {
					this.$vux.toast.text('服务器繁忙，请稍后再试');
				})
			},

		}
	}
</script>

<style lang="less" scoped>
	.outerDiv {
		width: 100%;
		height: 100vh;
		background: #fff;
		position: relative;

		.title {
			padding: 0 0.3rem;
			margin-bottom: 0.4rem;
			font-size: 0.44rem;
			font-weight: bold;
		}

		.footer {
			width: 7.5rem;
			height: 2rem;
			background: #fff;
			box-shadow: 0px -4px 10px 0px rgba(204, 204, 204, 0.2);
			padding: 0 0.3rem;
			position: fixed;
			bottom: 0;
			left: 0;

			.top {
				height: 1rem;
				padding-right: 0.68rem;
				color: #BBBBBB;
				display: flex;
				justify-content: space-between;
				align-items: center;

				.top_1 {
					font-size: 0.26rem;

					b {
						color: #222;
						font-weight: bold;
					}

					.num {
						margin-left: 0.2rem;

						b {
							color: #6CBF20;
							font-size: 0.4rem;
							margin-right: 0.07rem;
						}
					}
				}

				.top_2 {
					font-size: 0.26rem;
					font-weight: bold;
					color: rgba(187, 187, 187, 1);

				}
			}

			.bottom {
				display: flex;
				justify-content: space-between;

				.btn {
					// 					width: 3.3rem;
					// 					height: 0.7rem;
					outline: none;
					font-size: 0.28rem;
					font-weight: bold;
					border-radius: 10px;
					border: none;
					width: 4rem;
					height: 0.8rem;
					background: rgba(108, 191, 32, 1);
					border-radius: 0.4rem;
					margin: 0 auto;
				}

				.createNew {
					color: #fff;

				}

				.cre1 {
					background: #EEE;
				}

				.cre2 {
					background: #6CBF20;
				}

				.watchResult {
					background: #fff;
					border: 2px solid #eee;
					color: #999;
				}
			}
		}
	}
</style>
